package com.seek.service.imp;

import org.springframework.stereotype.Repository;

import com.seek.core.BaseServiceImpl;
import com.seek.model.entity.TInter;
import com.seek.service.AlipayService;

@Repository("alipayService")
public class AlipayServiceImp extends BaseServiceImpl<TInter> implements AlipayService{
	
//	private static Logger logger = LoggerFactory.getLogger(AlipayServiceImp.class);
//	
//	public static final String return_url = WebUtil.ROOT_URL + "/plugin/html/paysuccess.html";
//	public static final String notify_url = WebUtil.ROOT_URL + "/alipay/notify";
//	
//	public String alipayAppUnifiedOrder(Map<String, String> params) throws Exception {
//		String return_result_msg = "";
//		//获取客户端
//		AlipayClient alipayClient = AlipayAPIClientFactory.getAlipayClient();
////		AlipayClient alipayClient = new DefaultAlipayClient(
////				"https://openapi.alipay.com/gateway.do",
////				"2017030806108154",
////				"MIIEvgIBADANBgkqhkiG9w0BAQEFAASCBKgwggSkAgEAAoIBAQCPe1uo/639N1kJZ+y/C+43QKe5u6reUcjvurNYtz5xlJa6KdkBZgEzFm4Zz/s5QNsHhbF2E4zmWOCjplbFzGyIdeAwKfI+bwAyS/bYc0NGogSXuLODar+7l3jRPbf8yvXldkoX2PJJAdU13Hl58B1hsLInQbMXEvjshLeKMwfA+W2k3HwNLXMO+4prfTu2l33OZSk5yKjHCnBcozQigU/Wd7iThMoW+pC9zy5xpw7mflT0G/KFwcdqJu2S8IqLD/cdW0NNhSoGikdHFqVgwgzxGeKXvao+RMMLISNUkwWJ3Ll6qwc2XiPiuYzRmif8WMExf4E2rZLY3kK+xTYmkn45AgMBAAECggEBAI37cBSoDjBImN7p7CiRUcVzQYZV4xvkqoYvplHf4vbaJt1Jk+gCXKWFSKZaXSumtheXgKhraD55LLJEZBGP3MacfqCqoYCOrw8WhMpkJOq8YPcSWvFsrRahKXlFLdAFt5a9m0xF7lu4aJfH+J1lsm19QI4AQYxPxeum2Uj0fnPB2Sp7QsTLualR+0gG36JlKH5jEPBxzEBSWrXoS9qGY69JafjoQTXoogrPxL3BCRJo9cvW0JLsigKblc+sAHqMZG4jW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+/LemngoDGuo5cd55Ft6Lq8A12FDSzDAzk/lDEru3mBOA0Um4D99pdM7/TAl0U37w+7DKczoy5ryoYVC66sfvevylj7kRZbcs95mzdsrm2jfZtp44Bit8KU5rXl6EmGYeK2eAdMQHvnBgTS/d8KqOIZDdVzHq6jbD/mKIb+LBQcd7P1nnexDwWWjnpC1VkaJWiaBBMkggTi41GpjQOkZVBQVKg+OUQkQDI9OnKp5txm/yzAf4PdvfNd6ojpboHbod1uG2I7mB52sqowzBuySpt1PZQbwIDAQAB",
////				"RSA2");
//		
//		
//		AlipayTradeAppPayRequest request = new AlipayTradeAppPayRequest();
//		
//		SortedMap<String, String> bizContentParams = new TreeMap<String, String>();
//		bizContentParams.put("out_trade_no", params.get("orderId"));//订单编号或者外部商户号
//		bizContentParams.put("seller_id", AlipayServiceEnvConstants.SELLER_ID);//商户签约账号对应的支付宝用户账号
//		bizContentParams.put("partner", AlipayServiceEnvConstants.PARTNER);
//		bizContentParams.put("total_amount", MoneyUtil.divide(params.get("payMoney"), MoneyUtil.MONEY_SCALE));//支付金额,已元为单位
//		bizContentParams.put("subject", "购买商品");
//		bizContentParams.put("body", params.get("orderId"));
//        
//		String bizContents =  JSON.toJSONString(bizContentParams);
//		request.setBizContent(bizContents);
//		request.setReturnUrl(return_url);
//		request.setNotifyUrl(params.get("notifyUrl"));//回调地址
//		
//		try {
//		        //这里和普通的接口调用不同，使用的是sdkExecute
//		        AlipayTradeAppPayResponse response = alipayClient.sdkExecute(request);
//		        if(response.isSuccess()){
//		        	return_result_msg = response.getBody();//就是orderString 可以直接给客户端请求，无需再做处理。
//		        	logger.info("response:"+return_result_msg);
//		        }
//		    } catch (AlipayApiException e) {
//		        e.printStackTrace();
//		}
//	    return return_result_msg;
//	}
//	
//	@Override
//	public AlipayAppApiPayDto alipayJsUnifiedOrder(Map<String, String> params) throws Exception {
//		
//		String notify_url = WebUtil.ROOT_URL + "/alipay/notify";
//		
//		//获取客户端
//		AlipayClient alipayClient = AlipayAPIClientFactory.getAlipayClient();
//		AlipayTradeCreateRequest request = new AlipayTradeCreateRequest();
//		
//		SortedMap<String, String> bizContentParams = new TreeMap<String, String>();
//		bizContentParams.put("out_trade_no", params.get("orderId"));//订单编号或者外部商户号
//		bizContentParams.put("seller_id", AlipayServiceEnvConstants.PARTNER);//商户签约账号对应的支付宝用户ID
//		bizContentParams.put("total_amount", MoneyUtil.divide(params.get("payMoney"), MoneyUtil.MONEY_SCALE));//支付金额,已元为单位
//		bizContentParams.put("subject", "购买商品");
//		bizContentParams.put("body", params.get("orderId"));
//        
//		String bizContents =  JSON.toJSONString(bizContentParams);
//		request.setBizContent(bizContents);
//		
//		AlipayTradeCreateResponse response = alipayClient.execute(request);
//		AlipayAppApiPayDto payDto = new AlipayAppApiPayDto();
//		logger.info("response:result="+response.isSuccess()+"msg:"+response.getMsg()+"sub_msg:"+response.getCode()+response.getSubMsg());
//		if(response.isSuccess()){
//			logger.info("response:sucess="+"调用成功"+"response:body="+response.getBody());
//			JSONObject jsonObject = JSON.parseObject(response.getBody());
//			payDto.setAppId(AlipayServiceEnvConstants.APP_ID);
//			payDto.setPartner(AlipayServiceEnvConstants.PARTNER);
//			payDto.setCharSet(AlipayServiceEnvConstants.CHARSET);
//			payDto.setSubject("购买商品");
//			payDto.setBody(params.get("orderId"));
//			payDto.setOut_trade_no(params.get("orderId"));
//		    payDto.setReturn_url(return_url);
//			payDto.setNotify_url(notify_url);
//		    payDto.setSeller_id(AlipayServiceEnvConstants.SELLER_ID);
//		    payDto.setSign(jsonObject.getString("sign"));
//		} else {
//			throw new RuntimeException("msg:"+response.getMsg()+"sub_msg:"+response.getCode()+response.getSubMsg());
//		}
//		return payDto;
//	}
//	
//	
//
//	public static void main(String[] args) {
//		createAppPayOrder();
//	}
//	
//	public static void createAppPayOrder(){
//		//实例化客户端
//		AlipayClient alipayClient = new DefaultAlipayClient(
//				"https://openapi.alipay.com/gateway.do",
//				"2017030806108154",
//				"MIIEvgIBADANBgkqhkiG9w0BAQEF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eG/1toCUIxv3h2aW+Rzj0UDbN7W0wUX7GKR8VuEV3ltF/UDPk4180XTsCcrzesOMLuwEP3EIlNYunYc/M1f1eFaBlDp8JLJXMjPw+n6da2BNxQdFcR+VbXArgxkSWKYMgpjY7Mad9zXsJ1gGhfpEyEye6btmUT7ECgYAz0H+u702w+SvQZ38wVm3RDS8chva0h+tlHCy8eQHJYzK7U3qa5sOqcaYUvjhLplUE3gl/jYUyRiAuz1SLs+rRF1nMg8K4al4r1LXzhgezqfh/URJm9PdJFcondwYaOrOVIzW6wB4fJwO7kvf5Ol0iq56sv0hItJ7K8rVg89fjgQKBgBwVOcvTfSZnAAC5aCiK117P3lJ4uW2VDYL+R8lzG+G2n7srSoI/V/3YR7fomPZmHqCci7+tyo0QllVGSXbWWuLwA2hrxUOgmM7X8FuttS4/QUtmIm927Xa69Bdxh0K6GpETSK54kUUGHPyG1zsN8atdkFpTh7iefuDhR/NlXSI8",
//				"json",
//				"utf-8",
//				"MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAl3xLU+2GY69gHHhuJsNNLKnsC3BFY7TqGHOHomuWRffFOgScIV9HapuiHd+/LemngoDGuo5cd55Ft6Lq8A12FDSzDAzk/lDEru3mBOA0Um4D99pdM7/TAl0U37w+7DKczoy5ryoYVC66sfvevylj7kRZbcs95mzdsrm2jfZtp44Bit8KU5rXl6EmGYeK2eAdMQHvnBgTS/d8KqOIZDdVzHq6jbD/mKIb+LBQcd7P1nnexDwWWjnpC1VkaJWiaBBMkggTi41GpjQOkZVBQVKg+OUQkQDI9OnKp5txm/yzAf4PdvfNd6ojpboHbod1uG2I7mB52sqowzBuySpt1PZQbwIDAQAB",
//				"RSA2");
//		
//		//实例化具体API对应的request类,类名称和接口名称对应,当前调用接口名称：alipay.trade.app.pay
//		AlipayTradeAppPayRequest request = new AlipayTradeAppPayRequest();
//		//SDK已经封装掉了公共参数，这里只需要传入业务参数。以下方法为sdk的model入参方式(model和biz_content同时存在的情况下取biz_content)。
//		AlipayTradeAppPayModel model = new AlipayTradeAppPayModel();
//		model.setBody("我是测试数据");
//		model.setSubject("App支付测试Java");
//		model.setOutTradeNo("201703110938383");
//		model.setTimeoutExpress("30m");
//		model.setTotalAmount("0.01");
//		model.setProductCode("QUICK_MSECURITY_PAY");
//		
////		SortedMap<String, String> bizContentParams = new TreeMap<String, String>();
////		bizContentParams.put("out_trade_no", "2017898333");//订单编号或者外部商户号
////		bizContentParams.put("seller_id", AlipayServiceEnvConstants.SELLER_ID);//商户签约账号对应的支付宝账号
////		bizContentParams.put("partner", AlipayServiceEnvConstants.PARTNER);//商户签约账号对应的支付宝账号
////		bizContentParams.put("total_amount", "0.01");//支付金额,已元为单位
////		bizContentParams.put("subject", "购买商品");
////		bizContentParams.put("body", "23423423423");
//		
//		request.setBizModel(model);
//		//request.setBizContent(JSONObject.toJSONString(bizContentParams));
//		request.setReturnUrl(return_url);
//		request.setNotifyUrl("http://testauth.xiaohongquan.cn/alipay/notify");
//		try {
//		        //这里和普通的接口调用不同，使用的是sdkExecute
//		        AlipayTradeAppPayResponse response = alipayClient.sdkExecute(request);
//		        System.out.println(response.getBody());//就是orderString 可以直接给客户端请求，无需再做处理。
//		    } catch (AlipayApiException e) {
//		        e.printStackTrace();
//		}
//		
//	}

}
